//
//  CollectionCellForColumn.m
//  MY Project For Sport
//
//  Created by dllo on 16/3/3.
//  Copyright © 2016年 dilo. All rights reserved.
//

#import "CollectionCellForColumn.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "ModelForColumn.h"
#import <DKNightVersion.h>
#import "UIColor+Wonderful.h"

#define WIDTH self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height

@interface CollectionCellForColumn ()

@property (nonatomic, retain)UIImageView *image;
@property (nonatomic, retain)UILabel *labelForName;


@end

@implementation CollectionCellForColumn

- (void)dealloc {
    
    [_image release];
    [_labelForName release];
    [super dealloc];

}

-(instancetype)initWithFrame:(CGRect)frame {

    self = [super initWithFrame:frame];
    
    if (self) {
        
        [self createSubview];
        
        self.contentView.dk_backgroundColorPicker = DKColorWithColors([UIColor linenColor], [UIColor grayColor]);

    }
    return self;

}

- (void)createSubview {

    self.image = [[UIImageView alloc] init];
    [self.contentView addSubview:self.image];
    [_image release];
    
    self.labelForName = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelForName];
    [_labelForName release];
 
}

-(void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {

    self.image.frame = CGRectMake(5, 5, WIDTH - 10 , WIDTH - 10);
    self.image.layer.cornerRadius = (WIDTH - 10) / 2;
    self.image.layer.masksToBounds = YES;

    self.labelForName.frame = CGRectMake(5,WIDTH , WIDTH - 10, HEIGHT / 3 - 10 - 5);
}

-(void)passModelForColumn:(ModelForColumn *)model {

    [self.image sd_setImageWithURL:[NSURL URLWithString:model.pic]];
    self.labelForName.text = model.title;
    self.labelForName.font = [UIFont systemFontOfSize:12];
    self.labelForName.textAlignment = NSTextAlignmentCenter;

}


@end
